# @file         Makefile.build 
# @brief        makefile 文件
# @details      通用 makefile。
# @author       lzm
# @date         2021-06-10 10:30:00
# @version      v1.0
# @copyright    Copyright By lizhuming, All Rights Reserved
# 
# *******************************************************
# @LOG 修改日志:
# *******************************************************
# 


ARCH ?= x86
ifeq ($(ARCH),x86)
CROSS_COMPILE =
else
CROSS_COMPILE = arm-linux-gnueabihf-
endif
AS      = $(CROSS_COMPILE)as
LD      = $(CROSS_COMPILE)ld
CC      = $(CROSS_COMPILE)gcc
CPP    = $(CC) -E
AR      = $(CROSS_COMPILE)ar
NM     = $(CROSS_COMPILE)nm

STRIP   = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump

export AS LD CC CPP AR NM
export STRIP OBJCOPY OBJDUMP


CFLAGS := -Wall -O2 -g 
CFLAGS += -I $(shell pwd)/include

# 由于使用到线程，而线程不是linux的标准库，所以需要用到 -lpthread 
LDFLAGS := -lpthread

export CFLAGS LDFLAGS

TOPDIR := $(shell pwd)
export TOPDIR

TARGET := tcp_server


obj-y += $(patsubst %.c,%.o,$(shell ls *.c))


all : start_recursive_build $(TARGET)
	@echo $(TARGET) has been built !


start_recursive_build:
	make -C ./ -f $(TOPDIR)/Makefile.build


$(TARGET) : built-in.o
	$(CC) -o $(TARGET) built-in.o $(LDFLAGS)


clean:
	rm -f $(shell find -name "*.o")
	rm -f $(TARGET)


distclean:
	rm -f $(shell find -name "*.o")
	rm -f $(shell find -name "*.d")
	rm -f $(TARGET)
